home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / sortc.arc / FGETSS.C < prev    next >
Text File  |  1987-06-17  |  474b  |  26 lines

  1. /*
  2.  * fgetss() is like fgets() except that the terminating newline
  3.  * is removed.
  4.  */
  5. #include <stdio.h>
  6.  
  7. char *fgetss(s, n, iop)
  8. char *s;
  9. register FILE *iop;
  10. {
  11.    register c;
  12.    register char *cs;
  13.  
  14.    cs = s;
  15.    while ((c = getc(iop)) >= 0 && --n > 0)
  16.    {
  17.       *cs++ = c;
  18.       if (c == '\n')
  19.          break;
  20.    }
  21.    if (c < 0 && cs == s)
  22.       return(NULL);
  23.    cs[-1] = '\0';                  /* Overwrite newline as null    */
  24.    return(s);
  25. }
  26.